/*******************************************************************************
 * Copyright (c) 2010, 2030 www.mahao.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing;

import java.lang.reflect.Field;

/** 
 * ClassName: Test <br/> 
 * Function: TODO 功能描述 <br/> 
 * date: 2017年4月24日 上午10:25:30 <br/> 
 * 
 * @author Mmmmm 
 * @version  
 * @since JDK 1.8 
 */
public class Test {
	public static void main(String[] args) {
		String className = "cn.itlaobing.Person";
		try {
//			Class classN = Person.class;
//			Class classN = Class.forName("Person");
			Class classN = Class.forName(className);
			Person p = (Person) classN.newInstance();
			Field name = classN.getDeclaredField("name");
			name.setAccessible(true);
			name.set(p, "张三");
			Field age = classN.getDeclaredField("age");
			age.setAccessible(true);
			age.set(p, 20);
			System.out.println(p.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
